package com.yufei.infoExtractor.pfw.entity;

import java.sql.ResultSet;



import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

import com.yufei.infoExtractor.core.CollectionElementType;

@XmlRootElement
public class Seedsite extends Entity {


	@Override
	public String toString() {
		return "Seedsite [seedSiteId=" + seedSiteId + ", taskName=" + taskName
				+ ", siteName=" + siteName + ", domain=" + domain + ", status="
				+ status + ", isFetched=" + isFetched + ", siteDesc="
				+ siteDesc + ", ipadress=" + ipadress + ", protocolType="
				+ protocolType + ", requestExecuteJs=" + requestExecuteJs
				+ ", pattern=" + pattern + ", paginationRule=" + paginationRule
				+ ", passedSimilarityValue="
				+ passedSimilarityValue + ", crawlerTime=" + crawlerTime
				+ ", depth=" + depth + ", lastCrawleredTime="
				+ lastCrawleredTime + ", lastUpdatedTime=" + lastUpdatedTime
				+ "]";
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((crawlerTime == null) ? 0 : crawlerTime.hashCode());
		result = prime * result + ((depth == null) ? 0 : depth.hashCode());
		result = prime * result + ((domain == null) ? 0 : domain.hashCode());
		result = prime * result
				+ ((ipadress == null) ? 0 : ipadress.hashCode());
		result = prime * result
				+ ((isFetched == null) ? 0 : isFetched.hashCode());
		result = prime
				* result
				+ ((lastCrawleredTime == null) ? 0 : lastCrawleredTime
						.hashCode());
		result = prime * result
				+ ((lastUpdatedTime == null) ? 0 : lastUpdatedTime.hashCode());
		

		result = prime * result
				+ ((paginationRule == null) ? 0 : paginationRule.hashCode());
		result = prime
				* result
				+ ((passedSimilarityValue == null) ? 0 : passedSimilarityValue
						.hashCode());
		result = prime * result + ((pattern == null) ? 0 : pattern.hashCode());
		result = prime * result
				+ ((protocolType == null) ? 0 : protocolType.hashCode());
		result = prime * result + (requestExecuteJs ? 1231 : 1237);
		result = prime * result
				+ ((seedSiteId == null) ? 0 : seedSiteId.hashCode());
		result = prime * result
				+ ((siteDesc == null) ? 0 : siteDesc.hashCode());
		result = prime * result
				+ ((siteName == null) ? 0 : siteName.hashCode());
		result = prime * result + ((status == null) ? 0 : status.hashCode());
		result = prime * result
				+ ((taskName == null) ? 0 : taskName.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Seedsite other = (Seedsite) obj;
		if (crawlerTime == null) {
			if (other.crawlerTime != null)
				return false;
		} else if (!crawlerTime.equals(other.crawlerTime))
			return false;
		if (depth == null) {
			if (other.depth != null)
				return false;
		} else if (!depth.equals(other.depth))
			return false;
		if (domain == null) {
			if (other.domain != null)
				return false;
		} else if (!domain.equals(other.domain))
			return false;
		if (ipadress == null) {
			if (other.ipadress != null)
				return false;
		} else if (!ipadress.equals(other.ipadress))
			return false;
		if (isFetched == null) {
			if (other.isFetched != null)
				return false;
		} else if (!isFetched.equals(other.isFetched))
			return false;
		if (lastCrawleredTime == null) {
			if (other.lastCrawleredTime != null)
				return false;
		} else if (!lastCrawleredTime.equals(other.lastCrawleredTime))
			return false;
		if (lastUpdatedTime == null) {
			if (other.lastUpdatedTime != null)
				return false;
		} else if (!lastUpdatedTime.equals(other.lastUpdatedTime))
			return false;
		

		if (paginationRule == null) {
			if (other.paginationRule != null)
				return false;
		} else if (!paginationRule.equals(other.paginationRule))
			return false;
		if (passedSimilarityValue == null) {
			if (other.passedSimilarityValue != null)
				return false;
		} else if (!passedSimilarityValue.equals(other.passedSimilarityValue))
			return false;
		if (pattern == null) {
			if (other.pattern != null)
				return false;
		} else if (!pattern.equals(other.pattern))
			return false;
		if (protocolType == null) {
			if (other.protocolType != null)
				return false;
		} else if (!protocolType.equals(other.protocolType))
			return false;
		if (requestExecuteJs != other.requestExecuteJs)
			return false;
		if (seedSiteId == null) {
			if (other.seedSiteId != null)
				return false;
		} else if (!seedSiteId.equals(other.seedSiteId))
			return false;
		if (siteDesc == null) {
			if (other.siteDesc != null)
				return false;
		} else if (!siteDesc.equals(other.siteDesc))
			return false;
		if (siteName == null) {
			if (other.siteName != null)
				return false;
		} else if (!siteName.equals(other.siteName))
			return false;
		if (status == null) {
			if (other.status != null)
				return false;
		} else if (!status.equals(other.status))
			return false;
		if (taskName == null) {
			if (other.taskName != null)
				return false;
		} else if (!taskName.equals(other.taskName))
			return false;
		return true;
	}
final public static String MOBILE="mobile";
final public static String TELECOM="telecom";
final public static String UNICOM="unicom";
final public static Integer UN_CRAWLERED=0; 
final public static Integer IS_CRAWLERING=1; 
final public static Integer IS_CRAWLERED=2; 
//0表示未被回传，1表示已经回传
final public static Integer ISFETCHED=0;
	// Fields

	private String seedSiteId;
	private String taskName;
	//种子网址地址
	private String siteName;
	//种子网址域名
	private String domain;
	//爬取状态
	private Integer status=UN_CRAWLERED;
	private Integer isFetched=ISFETCHED;
	private String siteDesc="";
	private String ipadress="";
	private String protocolType;
	private boolean requestExecuteJs=true;
	private Pattern pattern;
	private PaginationRule paginationRule=null;
	   
	//指定被刺处理所用的Job实现类完整名称包含包名，类名
	
	

	public PaginationRule getPaginationRule() {
		return paginationRule;
	}
	@XmlElement
	public void setPaginationRule(PaginationRule paginationRule) {
		this.paginationRule = paginationRule;
	}
	public Pattern getPattern() {
		return pattern;
	}
	@XmlElement
	public void setPattern(Pattern pattern) {
		this.pattern = pattern;
	}
	
	private Double passedSimilarityValue=new Double(0.00);
	
	public Double getPassedSimilarityValue() {
		return passedSimilarityValue;
	}
	@XmlElement(name="passedSimilarityValue")
    public void setPassedSimilarityValue(Double passedSimilarityValue) {
		this.passedSimilarityValue = passedSimilarityValue;
	}
	

	public boolean isRequestExecuteJs() {
		return requestExecuteJs;
	}
	@XmlElement
	public void setRequestExecuteJs(boolean requestExecuteJs) {
		this.requestExecuteJs = requestExecuteJs;
	}
	//表示任务执行周期
	private String crawlerTime;
	public String getCrawlerTime() {
		return crawlerTime;
	}
	public void setCrawlerTime(String crawlerTime) {
		this.crawlerTime = crawlerTime;
	}
	public String getProtocolType() {
		return protocolType;
	}
	@XmlElement
	public void setProtocolType(String protocolType) {
		this.protocolType = protocolType;
	}
	//是否已回传
	public Integer getIsFetched() {
		return isFetched;
	}
	public void setIsFetched(Integer isFetched) {
		this.isFetched = isFetched;
	}
	public String getSiteDesc() {
		return siteDesc;
	}
	public void setSiteDesc(String siteDesc) {
		this.siteDesc = siteDesc;
	}
	public String getIpadress() {
		return ipadress;
	}
	public void setIpadress(String ipadress) {
		this.ipadress = ipadress;
	}
	public void setStatus(Integer status) {
		this.status = status;
	}
	public Integer getStatus() {
		return status;
	}
	//既可以表示递归抓取深度也可表示利用分页模板提取Url的时候的页数
	private Integer depth;
	//标识上次爬取结束时间
	private Date lastCrawleredTime;
	//标识上次更新结束时间
	private Date lastUpdatedTime;
	public Date getLastCrawleredTime() {
		return lastCrawleredTime;
	}

	public void setLastCrawleredTime(Date lastCrawleredTime) {
		this.lastCrawleredTime = lastCrawleredTime;
	}

	public Date getLastUpdatedTime() {
		return lastUpdatedTime;
	}

	public void setLastUpdatedTime(Date lastUpdatedTime) {
		this.lastUpdatedTime = lastUpdatedTime;
	}
	/** default constructor */
	public Seedsite() {
		super();
	}

	public String getSeedSiteId() {
		return seedSiteId;
	}

	public void setSeedSiteId(String seedSiteId) {
		this.seedSiteId = seedSiteId;
	}

	


	public String getTaskName() {
		return taskName;
	}
	@XmlElement
	public void setTaskName(String taskName) {
		this.taskName = taskName;
	}
	public String getSiteName() {
		return siteName;
	}
@XmlElement
	public void setSiteName(String siteName) {
		this.siteName = siteName;
	}

	public String getDomain() {
		return domain;
	}
@XmlElement
	public void setDomain(String domain) {
		this.domain = domain;
	}

	

	public Integer getDepth() {
		return depth;
	}
@XmlElement
	public void setDepth(Integer depth) {
		this.depth = depth;
	}
private List<UsefullLink> usefullLinks=new ArrayList<UsefullLink>();
/*public static List<Seedsite>  transferFromRs(ResultSet rs) throws SQLException{
	List<Seedsite> seeds=new ArrayList();
	Seedsite seed=null;
	while(rs.next()){
		seed=new Seedsite();
		seed.setSeedSiteId(rs.getString("seedsiteid"));
		seed.setTaskId(rs.getString("taskid"));
		seed.setDepth(rs.getInt("depth"));
		seed.setSiteName(rs.getString("siteName"));
		seed.setDomain(rs.getString("domain"));
		//seed.setLastCrawleredTime(rs.getDate("lastCrawleredTime"));
		//seed.setLastUpdatedTime(rs.getDate("lastUpdatedTime"));
		seed.setStatus(rs.getInt("status"));
		seed.setIsFetched(rs.getInt("isfetched"));
		seed.setSiteDesc(rs.getString("sitedesc"));
		seed.setIpadress(rs.getString("ipadress"));
		seed.setProtocolType(rs.getString("protocoltype"));
	//	seed.setCrawlerTime(rs.getString("crawlertime"));
		seed.setRequestExecuteJs(rs.getBoolean("requestExecuteJs"));
		seeds.add(seed);
	}
	return seeds;
}*/

public List<UsefullLink> getUsefullLinks() {
	return usefullLinks;
}
@XmlElementWrapper(name="usefullLinks")
@XmlElement(name="usefullLink")
public void setUsefullLinks(List<UsefullLink> usefullLinks) {
	this.usefullLinks = usefullLinks;
}
	

}